package 集合.LIST;

import java.util.ArrayList;
import java.util.Scanner;

public class ArrayListDemo5 {
    public static void main(String[] args) {
        ArrayList<ArrayListDemo4Student>list=new ArrayList<>();
        Scanner sc=new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            ArrayListDemo4Student stu=new ArrayListDemo4Student();
            System.out.println("请输入学生姓名");
            String name=sc.next();
            System.out.println("请输入学生年龄");
            int age=sc.nextInt();
            stu.setAge(age);
            stu.setName(name);
            list.add(stu);
        }
        System.out.println("集合的长度为："+list.size());
        System.out.print("[");
        for (int i = 0; i < list.size(); i++) {
            ArrayListDemo4Student stu=list.get(i);
            System.out.print(stu.getAge()+","+stu.getName()+",");

        }
        System.out.println("]");
    }
}
